import os
import shutil

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager
from selenium.webdriver.chrome.service import Service


def auto_get_driver_chrome():
    # 指定驱动目标位置
    folder_path = r'F:\webdriver_manager_downloaded_driver-root'
    # 路径拼接
    file_path = os.path.join(folder_path, 'chromedriver.exe')

    # 使用ChromeDriverManager安装ChromeDriver，并获取驱动程序的路径
    download_driver_path = ChromeDriverManager().install()
    # 复制文件到目标位置
    shutil.copy(download_driver_path, folder_path)

    return file_path
def auto_get_driver_edge():
    # 指定驱动目标位置
    folder_path = r'F:\webdriver_manager_downloaded_driver-root'
    # 路径拼接
    file_path = os.path.join(folder_path, 'msedgedriver.exe')

    # 使用ChromeDriverManager安装ChromeDriver，并获取驱动程序的路径
    download_driver_path = EdgeChromiumDriverManager().install()
    # 复制文件到目标位置
    shutil.copy(download_driver_path, folder_path)

    return file_path

def check_webdriver(file_path):
     service = Service(file_path)
     driver = webdriver.Chrome(service=service)
     driver.get('http://www.baodu.com')

if __name__ == '__main__':
    print(auto_get_driver_edge())

